package com.portal.innovation.webController;

import com.portal.innovation.common.R;
import com.portal.innovation.pojo.EnrollmentInfo;
import com.portal.innovation.pojo.News;
import com.portal.innovation.service.*;
import com.portal.innovation.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("index")
public class WebController {

    @Autowired
    private DictionaryConfigService configService;
    @Autowired
    private PhotoWallService photoWallService;
    @Autowired
    private FaqService faqService;
    @Autowired
    private TeacherInfoService teacherInfoService;
    @Autowired
    private NewsService newsService;
    @Autowired
    private EnrollmentInfoService enrollmentInfoService;

    @GetMapping("getValue")
    public R getValue(@RequestParam String key) {
        String value = configService.getValue(key);
        return R.ok().put("value", value);
    }

    //获取照片墙所有数据
    @GetMapping("getPhotoWallData")
    public R getPhotoWallData() {
        return R.ok().put("data", photoWallService.list());
    }

    //Faq
    @GetMapping("getFaqData")
    public R getFaqData() {
        return R.ok().put("data", faqService.list());
    }

    //教师
    @GetMapping("getTeacherData")
    public R getTeacherData() {
        return R.ok().put("data", teacherInfoService.list());
    }

    //新闻
    @PostMapping("getNewsData")
    public R getNewsData(@RequestBody HashMap params) {
        PageUtils pageUtils = newsService.conditionSearch(params);
        return R.ok().put("data", pageUtils);
    }

    //新闻详情
    @GetMapping("getNewsDetail/{id}")
    public R getNewsDetail(@PathVariable Integer id) {
        News news = newsService.getDetailById(id);
        return R.ok().put("news", news);
    }

    //报名
    @PostMapping("enrollment")
    public R getNewsData(@RequestBody EnrollmentInfo enrollmentInfo) {
        enrollmentInfoService.saveInfo(enrollmentInfo);
        return R.ok();
    }
}
